<template>
  <div class="body">
    <el-row class="mb8">
      <el-col :span="18">
        <el-button
          type="info"
          @click="shuaxin"
          icon="el-icon-refresh-right"
        ></el-button>
        <!-- <el-button type="success" @click="handleAdd" icon="el-icon-plus">上传</el-button> -->
      </el-col>
      <el-col :span="6" class="seach">
        <el-input
          v-model="params.keywords"
          placeholder="请输入关键字"
        ></el-input>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="seach"
        ></el-button>
      </el-col>
    </el-row>
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      class="table"
      height="100%"
    >
      <!-- <el-table-column align="center" type="selection" width="55"> </el-table-column> -->
      <!-- <el-table-column type="index" label="序号" width="50"></el-table-column> -->
      <el-table-column
        align="center"
        prop="biddingNumber"
        label="项目编号"
        show-overflow-tooltip
        width="200"
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="biddingProjectNumber"
        label="包号"
        show-overflow-tooltip
        width="200"
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="biddingProjectName"
        label="项目名称"
        show-overflow-tooltip
        width="300"
      >
      </el-table-column>
      <el-table-column align="center" prop="bidding_type" label="采购方式">
        <!-- <template slot-scope="scope">{{ scope.row.date }}</template> -->
      </el-table-column>
      <el-table-column
        align="center"
        prop="bidDeginTime"
        label="开标日期"
        width="180"
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="bidEndTime"
        label="截止日期"
        width="180"
      >
      </el-table-column>
      <!-- <el-table-column align="center" prop="content" label="采购需求内容" width="180" show-overflow-tooltip>
            </el-table-column> -->
      <el-table-column
        align="center"
        prop="marginAmount"
        label="工程造价"
        width="180"
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="source"
        label="信息来源"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="moneysourceTxt"
        label="资金来源"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column align="center" label="操作" width="180" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleAdd(scope.row)">上传</el-button>
          <el-button size="mini" @click="detailViews(scope.row)"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 上传资料 -->
    <el-dialog
      title="上传进度资料"
      :visible.sync="open"
      width="50%"
      :close-on-click-modal="false"
      v-dialogDrag
      custom-class="publicDialog"
    >
      <el-form ref="form" :model="form" label-width="120px" class="">
        <el-form-item label="申请编号 :">
          <el-input v-model="form.apply_number" disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="备注 :">
          <el-input type="textarea" v-model="form.remark"></el-input>
        </el-form-item>
        <el-form-item label="上传图片 :">
          <el-row :gutter="110">
            <el-col :span="24">
              <div
                class="avatar"
                v-show="form.pro_image.length > 0"
                v-for="(item, index) in form.pro_image"
                :key="index"
              >
                <img :src="item" />
                <i
                  class="el-icon-delete"
                  @click="zhengdeleteImg(index)"
                  style="z-index: 10"
                ></i>
              </div>
              <el-upload
                class="avatar-uploader"
                action="http://192.168.0.28:8082/handle/baohan/uploads"
                :show-file-list="false"
                :on-success="zhengSuccess"
              >
                <div class="avatar-uploader-icon">
                  <i class="el-icon-plus"></i>
                </div>
              </el-upload>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="上传视频 :">
          <el-upload
            class="upload-demo"
            ref="upload"
            action="http://192.168.0.28:8082/handle/baohan/uploads"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :file-list="fileList"
            :on-success="handleSuccess"
          >
            <el-button slot="trigger" size="small" type="primary"
              >选取文件</el-button
            >
          </el-upload>
        </el-form-item>
      </el-form>
      <div class="footer">
        <el-button type="" class="btn" @click="save">提交</el-button>
        <el-button type="" class="btn" @click="open = false">取消</el-button>
      </div>
    </el-dialog>

    <div class="block">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 30]"
        :current-page="params.pageSize"
        :page-size="params.pageNum"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
  
<script>
import { gclist, addpro } from "@/api/daihou.js";
export default {
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      params: {
        pageNum: 1,
        pageSize: 10,
        keywords: "",
      },
      total: null,
      // 表单参数
      form: {
        apply_number: "",
        pro_image: [],
        pro_video: [],
        remark: "",
      },
      // 表单校验
      rules: {},
      options1: [], //选择部门
      options2: [], //选择职位
      options3: [
        {
          value: "HTML",
          label: "HTML",
        },
        {
          value: "CSS",
          label: "CSS",
        },
        {
          value: "JavaScript",
          label: "JavaScript",
        },
      ], //选择小组
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4,
      tableData: [],
      multipleSelection: [],
    };
  },
  created() {
    this.lists();
  },

  methods: {
    // 列表
    lists() {
      gclist({ ...this.params }).then((response) => {
        console.log(response);
        this.tableData = response.data.rows;
        this.total = response.data.total;
        // this.tableData = [
        //   {
        //     bid_begin_time: "2022-11-30 09:00:00",
        //     bid_end_time: "2022-11-30 09:00:00",
        //     bidding_code: "415999907",
        //     bidding_number: "豫财招标采购-2022-1270",
        //     bidding_project_name:
        //       "河南省民政学校幼儿保育专业产教融合实训基地建设项目",
        //     bidding_project_number: "豫政采(2)20221986-1",
        //     bidding_type: "公开招标",
        //     content:
        //       "5.1 本项目采购内容：河南省民政学校幼儿保育专业产教融合实训基地建设，具体采购需求详见附件。<br/>5.2 资金来源：财政资金。<br/>5.3 交货期：合同生效之日起，45 日历天内供货、安装、调试完毕。<br/>5.4 质保期： 3 年。<br/>5.5 交货地点：采购人指定地点。<br/>6、合同履行期限：同交货及安装调试期。",
        //     create_time: "2022-11-15 14:27:20",
        //     html_base64_str: null,
        //     margin_amount: "1190000",
        //     moneysource: 0,
        //     moneysource_txt: "政府资金",
        //     other: null,
        //     proid: 68,
        //     purchase_person_name: "河南省民政学校",
        //     source: "系统",
        //     status: 0,
        //   },
        // ];
        // this.total = 1;
      });
    },
    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.params.pageSize = val;
      this.lists();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.params.pageNum = val;
      this.lists();
    },
    // 搜索
    seach() {
      // this.params.offset = 1;
      // this.params.limit = 10;
      this.lists();
    },

    shuaxin() {
      this.params.pageNum = 1;
      this.params.pageSize = 10;
      this.lists();
    },

    // 详情
    detailViews(val) {
      this.$router.push({
        path: "/daihouguanli/detail",
        query: {
          id: val.proid,
        },
      });
    },
    handleAdd(val) {
      (this.form = {
        apply_number: "",
        pro_image: [],
        pro_video: [],
        remark: "",
      }),
        (this.open = true);
      this.form.apply_number = val.bhlist.apply_number;
    },
    handleRemove(file) {
      console.log(file);
    },
    handleSuccess(res) {
      console.log(res);
      if (res.code == 1) {
        this.form.pro_video.push(res.data.fullurl);
      } else {
        this.$message({
          message: res.msg,
          type: "warning",
        });
      }
    },
    handlePreview(res) {
      console.log(res);
    },
    zhengSuccess(res) {
      console.log(res);
      if (res.code == 1) {
        this.form.pro_image.push(res.data.fullurl);
      } else {
        this.$message({
          message: res.msg,
          type: "warning",
        });
      }
    },
    // 删除图片
    zhengdeleteImg(index) {
      this.$confirm("确定删除此图片吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.form.pro_image.splice(index, 1);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    save() {
      this.form.pro_image = this.form.pro_image.join(",");
      this.form.pro_video = this.form.pro_video.join(",");
      addpro({ ...this.form }).then((res) => {
        if (res.code == 1) {
          this.open = false;
          (this.form = {
            apply_number: "",
            pro_image: [],
            pro_video: [],
            remark: "",
          }),
            this.$message({
              message: res.msg,
              type: "success",
            });
        } else {
          this.$message({
            message: res.msg,
            type: "warning",
          });
        }
      });
    },
  },
};
</script>
  
<style scoped lang="scss">
.body {
  height: calc(90vh - 60px);
  display: flex;
  flex-direction: column;
}

.table {
  width: 100%;
  margin-top: 10px;
}

.block {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding-top: 0 !important;
  padding-bottom: 10px;
}

// 新增弹窗上传图片
.avatar-uploader {
  width: 49%;
}

::v-deep .avatar-uploader .el-upload {
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  width: 100%;
}

.avatar-uploader-icon {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 4px 4px 4px 4px;
  border: 1px dashed rgba(0, 0, 0, 0.15);
  font-size: 14px;
  color: #8c939d;
  width: 100%;
  height: 138px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  .el-icon-plus {
    font-size: 28px;
  }
}

.avatar {
  width: 46%;
  height: 138px;
  display: flex;
  align-items: center;
  font-size: 20px;
  margin-bottom: 8px;
  margin-right: 10px;

  img {
    width: 100%;
    height: 100%;
    margin-right: 8px;
  }
}

.el-row {
  margin: 0 !important;
}

.el-col-24 {
  padding: 0 !important;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
</style>
  